﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Specialized;

namespace V5_WebControls
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:LabelTextBox runat=server></{0}:LabelTextBox>")]
    public class LabelTextBox : WebControl, INamingContainer
    {
        public string Text
        {
            get
            {
                object o = ViewState["Text"];
                if (o == null)
                    return String.Empty;
                return (string)o;
            }
            set { ViewState["Text"] = value; }
        }
        public string Title
        {
            get
            {
                object o = ViewState["Title"];
                if (o == null)
                    return String.Empty;
                return (string)o;
            }
            set { ViewState["Title"] = value; }
        }
        protected override void CreateChildControls()
        {
            Controls.Clear();
            //CreateControlHierarchy();
            ClearChildViewState();
        }
        //protected virtual void CreateControlHierarchy()
        //{
        //    TextBox t = new TextBox();
        //    Label l = new Label();
        //    t.Text = Text;
        //    l.Text = Title;
        //    Controls.Add(l);
        //    Controls.Add(t);
        //}

        protected override void Render(HtmlTextWriter writer)
        {
            string markup = String.Format(
 "<span>{0}</span><input type=text value='{1}' name='{2}'>",
 Title, Text, ClientID);
            markup += String.Format(
 "<span>{0}</span><input type=text value='{1}' name='{2}'>",
 Title, Text, ClientID);
            markup += String.Format(
 "<span>{0}</span><input type=text value='{1}' name='{2}'>",
 Title, Text, ClientID);
            writer.Write(markup);
        }
    }

}
